package sqlhelper

Import Path
	github.com/Golang-Tools/sqlhelper (on go.dev)

Dependency Relation
	imports 17 packages, and imported by 0 packages

Involved Source Files excptions.go options.go proxy.go
Package-Level Type Names (total 5, in which 4 are exported)
/* sort exporteds by: | */
Callback redis操作的回调函数 func (*Proxy).Regist(cb Callback) error
Option configures how we set up the connection. ( T) Apply(*Options) func WithConnMaxIdleTimeMS(ConnMaxIdleTimeMS int) Option func WithConnMaxLifetimeMS(ConnMaxLifetimeMS int) Option func WithDiscardUnknownColumns() Option func WithInstance(cli *bun.DB) Option func WithLogger(logger logrus.FieldLogger) Option func WithMaxIdleConns(MaxIdleConns int) Option func WithMaxOpenConns(MaxOpenConns int) Option func WithParallelCallback() Option func WithQueryTimeoutMS(QueryTimeout int) Option func WithURL(URL string) Option func (*Proxy).Init(opts ...Option) error
Option 设置key行为的选项 @attribute MaxTTL time.Duration 为0则不设置过期 @attribute AutoRefresh string 需要为crontab格式的字符串,否则不会自动定时刷新 // 只在Init方法中生效 ConnMaxIdleTime time.Duration ConnMaxLifetime time.Duration DiscardUnknownColumns bool Logger logrus.FieldLogger MaxIdleConns int MaxOpenConns int // 只在Init方法中生效 // 只在Init方法中生效 // 只在Init方法中生效 func NewDB(URL string, dopts *Options) (*bun.DB, error) func SetPool(sqldb *sql.DB, opts *Options) func Option.Apply(*Options) var DefaultOpts
Proxy bun客户端的代理 DB *bun.DB ( T) AddQueryHook(hook bun.QueryHook) ( T) Begin() (bun.Tx, error) ( T) BeginTx(ctx context.Context, opts *sql.TxOptions) (bun.Tx, error) Close closes the database and prevents new queries from starting. Close then waits for all queries that have started processing on the server to finish. It is rare to Close a DB, as the DB handle is meant to be long-lived and shared between many goroutines. ( T) Conn(ctx context.Context) (bun.Conn, error) ( T) DBStats() bun.DBStats ( T) Dialect() schema.Dialect Driver returns the database's underlying driver. ( T) Exec(query string, args ...interface{}) (sql.Result, error) ( T) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error) ( T) Formatter() schema.Formatter Init 初始化代理对象 IsOk 检查代理是否已经可用 ( T) NewAddColumn() *bun.AddColumnQuery ( T) NewCreateIndex() *bun.CreateIndexQuery ( T) NewCreateTable() *bun.CreateTableQuery NewCtx 根据注册的超时时间构造一个上下文 ( T) NewDelete() *bun.DeleteQuery ( T) NewDropColumn() *bun.DropColumnQuery ( T) NewDropIndex() *bun.DropIndexQuery ( T) NewDropTable() *bun.DropTableQuery ( T) NewInsert() *bun.InsertQuery ( T) NewSelect() *bun.SelectQuery ( T) NewTruncateTable() *bun.TruncateTableQuery ( T) NewUpdate() *bun.UpdateQuery ( T) NewValues(model interface{}) *bun.ValuesQuery Ping verifies a connection to the database is still alive, establishing a connection if necessary. PingContext verifies a connection to the database is still alive, establishing a connection if necessary. ( T) Prepare(query string) (bun.Stmt, error) ( T) PrepareContext(ctx context.Context, query string) (bun.Stmt, error) ( T) Query(query string, args ...interface{}) (*sql.Rows, error) ( T) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error) ( T) QueryRow(query string, args ...interface{}) *sql.Row ( T) QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row Regist 注册回调函数,在init执行后执行回调函数 如果对象已经设置了被代理客户端则无法再注册回调函数 ( T) RegisterModel(models ...interface{}) ( T) ResetModel(ctx context.Context, models ...interface{}) error RunInTx runs the function in a transaction. If the function returns an error, the transaction is rolled back. Otherwise, the transaction is committed. ( T) ScanRow(ctx context.Context, rows *sql.Rows, dest ...interface{}) error ( T) ScanRows(ctx context.Context, rows *sql.Rows, dest ...interface{}) error SetConnMaxIdleTime sets the maximum amount of time a connection may be idle. Expired connections may be closed lazily before reuse. If d <= 0, connections are not closed due to a connection's idle time. SetConnMaxLifetime sets the maximum amount of time a connection may be reused. Expired connections may be closed lazily before reuse. If d <= 0, connections are not closed due to a connection's age. SetConnect 设置连接的客户端 @params cli *bun.DB bun的DB对象 SetMaxIdleConns sets the maximum number of connections in the idle connection pool. If MaxOpenConns is greater than 0 but less than the new MaxIdleConns, then the new MaxIdleConns will be reduced to match the MaxOpenConns limit. If n <= 0, no idle connections are retained. The default max idle connections is currently 2. This may change in a future release. SetMaxOpenConns sets the maximum number of open connections to the database. If MaxIdleConns is greater than 0 and the new MaxOpenConns is less than MaxIdleConns, then MaxIdleConns will be reduced to match the new MaxOpenConns limit. If n <= 0, then there is no limit on the number of open connections. The default is 0 (unlimited). SetQueryTimeout 设置连接的请求超时 @params timeout time.Duration Stats returns database statistics. ( T) String() string ( T) Table(typ reflect.Type) *schema.Table ( T) WithNamedArg(name string, value interface{}) *bun.DB T : github.com/uptrace/bun.IConn T : github.com/uptrace/bun.IDB T : fmt.Stringer T : io.Closer func New() *Proxy var DB *Proxy
Package-Level Functions (total 14, in which 13 are exported)
New 创建一个新的数据库客户端代理
func NewDB(URL string, dopts *Options) (*bun.DB, error)
SetPool 设置连接池信息
WithConnMaxIdleTimeMS 设置连接池的最大空闲连接超时时间,单位ms
WithConnMaxLifetimeMS 设置连接池的最大连接超时时间,单位ms
WithDiscardUnknownColumns 设置当有未知列时不报错
WithLogger 用于添加logger方便debug
WithMaxIdleConns 设置连接池的最大空闲连接数
WithMaxOpenConns 设置连接池的最大连接数
WithParallelCallback 设置初始化后回调并行执行而非串行执行
WithQueryTimeoutMS 设置最大请求超时,单位ms
WithURL 使用要连接的数据库管理系统的url
Package-Level Variables (total 6, all are exported)
DB 默认的数据库代理对象
ErrProxyAllreadySettedUniversalClient 代理已经设置过redis客户端对象
ErrProxyNotYetSettedUniversalClient 代理还未设置客户端对象
ErrUnknownClientType 未知的redis客户端类型
ErrUnSupportSchema 未支持的数据库管理服务类型